Skip to content

Fix IPAddr#== returning true when compared with nil for 0.0.0.0 and ::#76

Merged
taketo1113 merged 1 commit intoruby:masterfrom
taketo1113:equal-nil
Apr 24, 2026
Merged

Fix IPAddr#== returning true when compared with nil for 0.0.0.0 and ::#76
taketo1113 merged 1 commit intoruby:masterfrom
taketo1113:equal-nil

Conversation

@taketo1113
Copy link
Copy Markdown
Collaborator

@taketo1113 taketo1113 commented Aug 27, 2024

IPAddr.new("0.0.0.0") == nil and nil == IPAddr.new("0.0.0.0") return different results.

This Pull Request fixes IPAddr.new("0.0.0.0") == nil so that it returns false, consistent with the behavior of IPAddr.new("0.0.0.0").nil?.

Steps to reproduce

# IPv4
IPAddr.new("0.0.0.0") == nil
#=> true # expected false

nil == IPAddr.new('0.0.0.0')
#=> false

IPAddr.new("0.0.0.0").nil?
#=> false

# IPv6
IPAddr.new("::") == nil
#=> true # expected false

nil == IPAddr.new("::")
#=> false

IPAddr.new("::").nil?
#=> false

Expected behavior

IPAddr.new("0.0.0.0") == nil should return false, just like IPAddr.new("0.0.0.0").nil?.

Actual behavior

IPAddr.new("0.0.0.0") == nil return true.

System configuration

  • IPAddr version: 1.2.8
  • Ruby version: 4.0.1
    • ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [arm64-darwin25]

Additional Information

This issue was discovered while investigating the following report:

@taketo1113 taketo1113 requested a review from knu as a code owner August 27, 2024 13:50
@taketo1113 taketo1113 changed the title ==: Fix comparing to nil ==: Fix comparing '0.0.0.0'/'::' to nil Aug 29, 2024
Copy link
Copy Markdown

@Bom123789 Bom123789 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test/test_ipaddr.rb

@taketo1113 taketo1113 changed the title ==: Fix comparing '0.0.0.0'/'::' to nil Fix IPAddr#== returning true when compared with nil for 0.0.0.0 and :: Mar 7, 2026
@taketo1113
Copy link
Copy Markdown
Collaborator Author

The codebase had become outdated, so I rebased it.
I also rewrote the Pull Request description, adding reproduction steps and details about the actual behavior.

@taketo1113 taketo1113 merged commit 53b9303 into ruby:master Apr 24, 2026
31 checks passed
@taketo1113 taketo1113 deleted the equal-nil branch April 24, 2026 22:54
@taketo1113
Copy link
Copy Markdown
Collaborator Author

In typical usage, the unexpected behavior may simply go unnoticed, and I believe there are no breaking compatibility concerns that would cause any users to depend on the previous behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPAddr.new("0.0.0.0") == nil and nil == IPAddr.new("0.0.0.0") return different results

2 participants